package com.drools.demo.server;

import com.drools.demo.entity.Person;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author czq
 * @Package com.drools.demo.server
 * @Date 2024/8/27 14:37
 * @description:
 */
@Service
public class PersonService {
    @Resource
    private KieContainer kieContainer;

    public Person calculateRule1(Person person) {
        KieSession kieSession = kieContainer.newKieSession();
        kieSession.getAgenda().getAgendaGroup("rule1").setFocus();
        kieSession.insert(person);
        kieSession.fireAllRules();
        kieSession.dispose();
        return person;
    }

    public Person calculateRule2(Person person) {
        KieSession kieSession = kieContainer.newKieSession();
        kieSession.getAgenda().getAgendaGroup("rule2").setFocus();
        kieSession.insert(person);
        kieSession.fireAllRules();
        kieSession.dispose();
        return person;
    }
}
